package servlet;

import bean.Result;
import biz.BizException;
import biz.ProductBiz;
import biz.ProductTypeBiz;
import com.google.gson.Gson;
import dao.ProductTypeDao;
import util.ProjectUitl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SaveMiniTypeServlet", value = "/SaveMiniTypeServlet.s")
public class SaveMiniTypeServlet extends HttpServlet {
    private ProductTypeBiz biz = new ProductTypeBiz();
    private ProductTypeDao dao = new ProductTypeDao();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String typedetailid = request.getParameter("typedetailid");
        final String name = request.getParameter("name");
        final String tname = request.getParameter("tname");

        Result result = null;
        try {
            biz.saveMiniType(name,typedetailid,tname);
            result = new Result(1,"保存成功!",null);
        }catch (BizException e){
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
        }catch (Exception e){
            e.printStackTrace();
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
